﻿// Created by:  Tomer Shamam
// Date:        06-Feb-2009
// From:        http://blogs.microsoft.co.il/blogs/tomershamam/archive/2007/10/30/wpf-localization-on-the-fly-language-selection.aspx

using System;
using System.Globalization;
using System.ComponentModel;

namespace ScrumTable.UI.View.Localization
{
    public sealed class LanguageProvider : ISupportInitialize
    {
        #region Fields

        private Type _dictionaryType;
        private CultureInfo _culture;
        private object _parameter; 

        #endregion

        #region Properties

        public Type DictionaryType
        {
            get { return _dictionaryType; }
            set { _dictionaryType = value; }
        }

        public CultureInfo Culture
        {
            get { return _culture; }
            set { _culture = value; }
        }

        public object Parameter
        {
            get { return _parameter; }
            set { _parameter = value; }
        }
 
        #endregion

        #region ISupportInitialize Members

        public void BeginInit()
        {
        }

        public void EndInit()
        {
            object instance = Activator.CreateInstance(_dictionaryType, new object[] {_parameter});
            LanguageDictionary dictionary = instance as LanguageDictionary;
            LanguageDictionary.RegisterDictionary(_culture, dictionary);
        }

        #endregion
    }
}